<template>
  <div>
    <van-nav-bar title="登录" left-arrow @click-left="$router.replace('/home')">
      <template #right>
        <van-icon name="ellipsis" size="18" color="#000" />
      </template>
    </van-nav-bar>
    <img src="../assets/mlogo.png" alt="" class="mlogo" />
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div class="yzm" style="margin: 20px;">
        <div class="left">
          58 + 32 = ？
        </div>
        <input type="text" class="right" />
        <span>换一张</span>
      </div>
      <p class="ljzc">立即注册</p>
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { mapMutations } from "vuex";
export default {
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    ...mapMutations(["SET_USER"]),
    onSubmit(username) {
      this.SET_USER({
        username,
        isLogin: true,
      });
      this.$router.replace("/home");
    },
  },
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
}
.van-icon-arrow-left::before {
  color: #000;
}
.van-nav-bar__content {
  height: 56px;
}
.mlogo {
  width: 154px;
  height: 154px;
  display: block;
  margin: 50px auto 0;
}
.van-button {
  background: #1baeae;
}
.left {
  width: 40%;
  text-align: center;
  height: 40px;
  line-height: 40px;
  border: 1px solid #ddd;
  font-size: 16px;
  background-color: rgb(240, 255, 240);
  color: rgb(0, 102, 153);
}
.yzm {
  height: 40px;
  display: flex;
  justify-content: space-between;
}
.right {
  width: 30%;
  text-align: center;
  height: 38px;
  line-height: 38px;
  border: 1px solid #ddd;
  font-size: 16px;
}
.yzm > span {
  font-size: 12px;
  color: #337ab7;
  line-height: 40px;
}
.ljzc {
  padding: 0 5%;
  box-sizing: border-box;
  color: #1989fa;
  font-size: 18px;
}
</style>
